clear
set memory 300m
set matsize 800
set more off
log using table2b.log ,replace

use kugcob

keep grup dcobseu dman d20_59 country year dcobneu1 dtic1_5 demp dinact limit1 countryb trend isced
drop if trend<1995

/* Generate the Yugoslavia dummies for Nationality and Nativity */

generate yugnativ=(countryb=="26") if trend>=1992 & trend<=1995
replace yugnativ=(countryb=="BA"|countryb=="HR"|countryb=="YU") if trend>=1996

/* Drop years for which e/p and lfp are not available */

egen dempck1=sum(demp) if (yugnativ==1 & dman==1 & d20_59==1 & dtic1_5==1), by(country year)
egen dempck2=sum(demp) if (yugnativ==1 & dman==0 & d20_59==1 & dtic1_5==1), by(country year)
egen dempck3=sum(demp) if (yugnativ==1 & dman==1 & d20_59==1 & dtic1_5==0), by(country year)
egen dempck4=sum(demp) if (yugnativ==1 & dman==0 & d20_59==1 & dtic1_5==0), by(country year)

gen dinact2=(dinact==0)

egen dinack1=sum(dinact2) if (yugnativ==1 & dman==1 & d20_59==1 & dtic1_5==1), by(country year)
egen dinack2=sum(dinact2) if (yugnativ==1 & dman==0 & d20_59==1 & dtic1_5==1), by(country year)
egen dinack3=sum(dinact2) if (yugnativ==1 & dman==1 & d20_59==1 & dtic1_5==0), by(country year)
egen dinack4=sum(dinact2) if (yugnativ==1 & dman==0 & d20_59==1 & dtic1_5==0), by(country year)

drop if dempck1==0 | dempck2==0 | dempck3==0 | dempck4==0
drop if dinack1==0 | dinack2==0 | dinack3==0 | dinack4==0

/* Table 3: Panels A & B, Labor Force Participation Rate and Employment/Population */

/* Generate Total Populations and Total Employed for Each Group by Nativity and Nationality */

egen mpnati=sum(grup) if (dcobseu==1 & dman==1 & d20_59==1), by(country year)
egen wpnati=sum(grup) if (dcobseu==1 & dman==0 & d20_59==1), by(country year)

egen mpfrneu=sum(grup) if (dcobneu1==1 & dtic1_5==1 & dman==1 & d20_59==1), by(country year)
egen wpfrneu=sum(grup) if (dcobneu1==1 & dtic1_5==1 & dman==0 & d20_59==1), by(country year)

egen mpfvneu=sum(grup) if (dcobneu1==1 & dtic1_5==0 & dman==1 & d20_59==1), by(country year)
egen wpfvneu=sum(grup) if (dcobneu1==1 & dtic1_5==0 & dman==0 & d20_59==1), by(country year)


egen menati=sum(grup) if (dcobseu==1 & demp==1 & dman==1 & d20_59==1), by(country year)
egen wenati=sum(grup) if (dcobseu==1 & demp==1 & dman==0 & d20_59==1), by(country year)

egen mefrneu=sum(grup) if (dcobneu1==1 & demp==1 & dtic1_5==1 & dman==1 & d20_59==1), by(country year)
egen wefrneu=sum(grup) if (dcobneu1==1 & demp==1 & dtic1_5==1 & dman==0 & d20_59==1), by(country year)

egen mefvneu=sum(grup) if (dcobneu1==1 & demp==1 & dtic1_5==0 & dman==1 & d20_59==1), by(country year)
egen wefvneu=sum(grup) if (dcobneu1==1 & demp==1 & dtic1_5==0 & dman==0 & d20_59==1), by(country year)


egen mlfnati=sum(grup) if (dcobseu==1 & dinact==0 & dman==1 & d20_59==1), by(country year)
egen wlfnati=sum(grup) if (dcobseu==1 & dinact==0 & dman==0 & d20_59==1), by(country year)

egen mlffrneu=sum(grup) if (dcobneu1==1 & dinact==0 & dtic1_5==1 & dman==1 & d20_59==1), by(country year)
egen wlffrneu=sum(grup) if (dcobneu1==1 & dinact==0 & dtic1_5==1 & dman==0 & d20_59==1), by(country year)

egen mlffvneu=sum(grup) if (dcobneu1==1 & dinact==0 & dtic1_5==0 & dman==1 & d20_59==1), by(country year)
egen wlffvneu=sum(grup) if (dcobneu1==1 & dinact==0 & dtic1_5==0 & dman==0 & d20_59==1), by(country year)

sort country year
* save ~/work/migration/newdata/yugemp95.dta ,replace

by country year: generate me_pnati=(menati/mpnati)
by country year: generate we_pnati=(wenati/wpnati)

by country year: generate me_pfrne=(mefrneu/mpfrneu)
by country year: generate we_pfrne=(wefrneu/wpfrneu)

by country year: generate me_pfvne=(mefvneu/mpfvneu)
by country year: generate we_pfvne=(wefvneu/wpfvneu)


by country year: generate ml_pnati=(mlfnati/mpnati)
by country year: generate wl_pnati=(wlfnati/wpnati)

by country year: generate ml_pfrne=(mlffrneu/mpfrneu)
by country year: generate wl_pfrne=(wlffrneu/wpfrneu)

by country year: generate ml_pfvne=(mlffvneu/mpfvneu)
by country year: generate wl_pfvne=(wlffvneu/wpfvneu)

* EMP/POP - NATIVES
by country : summarize me_pnati
by country : summarize we_pnati
* EMP/POP - NONEU RECENT
by country : summarize me_pfrne
by country : summarize we_pfrne
* EMP/POP - NONEU VETERAN
by country : summarize me_pfvne
by country : summarize we_pfvne

* LFP - NATIVES
by country : summarize ml_pnati
by country : summarize wl_pnati
* LFP - NONEU RECENT
by country : summarize ml_pfrne
by country : summarize wl_pfrne
* LFP - NONEU VETERAN
by country : summarize ml_pfvne
by country : summarize wl_pfvne


/* Generate Total Populations and Total Employed for Yugoslavians by Nativity and Nationality by Recent or Veteran */

egen mpyg1_5=sum(grup) if (yugnativ==1 & dtic1_5==1 & dman==1 & d20_59==1), by(country year)
egen wpyg1_5=sum(grup) if (yugnativ==1 & dtic1_5==1 & dman==0 & d20_59==1), by(country year)
egen mpyg6_9=sum(grup) if (yugnativ==1 & dtic1_5==0 & dman==1 & d20_59==1), by(country year)
egen wpyg6_9=sum(grup) if (yugnativ==1 & dtic1_5==0 & dman==0 & d20_59==1), by(country year)

egen meyg1_5=sum(grup) if (yugnativ==1 & dtic1_5==1 & demp==1 & dman==1 & d20_59==1), by(country year)
egen weyg1_5=sum(grup) if (yugnativ==1 & dtic1_5==1 & demp==1 & dman==0 & d20_59==1), by(country year)
egen meyg6_9=sum(grup) if (yugnativ==1 & dtic1_5==0 & demp==1 & dman==1 & d20_59==1), by(country year)
egen weyg6_9=sum(grup) if (yugnativ==1 & dtic1_5==0 & demp==1 & dman==0 & d20_59==1), by(country year)

egen mlyg1_5=sum(grup) if (yugnativ==1 & dtic1_5==1 & dinact==0 & dman==1 & d20_59==1), by(country year)
egen wlyg1_5=sum(grup) if (yugnativ==1 & dtic1_5==1 & dinact==0 & dman==0 & d20_59==1), by(country year)
egen mlyg6_9=sum(grup) if (yugnativ==1 & dtic1_5==0 & dinact==0 & dman==1 & d20_59==1), by(country year)
egen wlyg6_9=sum(grup) if (yugnativ==1 & dtic1_5==0 & dinact==0 & dman==0 & d20_59==1), by(country year)

/*
/* Identifying Observations Under Limit of Reliability of EUROSTAT */

generate smpyg1_5=1000*mpyg1_5
generate swpyg1_5=1000*wpyg1_5
generate smpyg6_9=1000*mpyg6_9
generate swpyg6_9=1000*wpyg6_9

generate smeyg1_5=1000*meyg1_5
generate sweyg1_5=1000*weyg1_5
generate smeyg6_9=1000*meyg6_9
generate sweyg6_9=1000*weyg6_9

generate smlyg1_5=1000*mlyg1_5
generate swlyg1_5=1000*wlyg1_5
generate smlyg6_9=1000*mlyg6_9
generate swlyg6_9=1000*wlyg6_9


generate lmpyg1_5=(smpyg1_5<limit1)
generate lwpyg1_5=(swpyg1_5<limit1)
generate lmpyg6_9=(smpyg6_9<limit1)
generate lwpyg6_9=(swpyg6_9<limit1)

generate lmeyg1_5=(smeyg1_5<limit1)
generate lweyg1_5=(sweyg1_5<limit1)
generate lmeyg6_9=(smeyg6_9<limit1)
generate lweyg6_9=(sweyg6_9<limit1)

generate lmlyg1_5=(smlyg1_5<limit1)
generate lwlyg1_5=(swlyg1_5<limit1)
generate lmlyg6_9=(smlyg6_9<limit1)
generate lwlyg6_9=(swlyg6_9<limit1)


replace mpyg1_5=. if lmpyg1_5==1
replace wpyg1_5=. if lwpyg1_5==1
replace mpyg6_9=. if lmpyg6_9==1
replace wpyg6_9=. if lwpyg6_9==1

replace meyg1_5=. if lmeyg1_5==1
replace weyg1_5=. if lweyg1_5==1
replace meyg6_9=. if lmeyg6_9==1
replace weyg6_9=. if lweyg6_9==1

replace mlyg1_5=. if lmlyg1_5==1
replace wlyg1_5=. if lwlyg1_5==1
replace mlyg6_9=. if lmlyg6_9==1
replace wlyg6_9=. if lwlyg6_9==1
*/
sort country year
* save ~/work/migration/newdata/yugemp95.dta, replace


by country year: generate me_pyg15=(meyg1_5/mpyg1_5)
by country year: generate me_pyg69=(meyg6_9/mpyg6_9)

by country year: generate we_pyg15=(weyg1_5/wpyg1_5)
by country year: generate we_pyg69=(weyg6_9/wpyg6_9)

by country year: generate ml_pyg15=(mlyg1_5/mpyg1_5)
by country year: generate ml_pyg69=(mlyg6_9/mpyg6_9)

by country year: generate wl_pyg15=(wlyg1_5/wpyg1_5)
by country year: generate wl_pyg69=(wlyg6_9/wpyg6_9)

* EMP/POP - YUG RECENT
by country : summarize me_pyg15
by country : summarize we_pyg15
* EMP/POP - YUG VETERAN
by country : summarize me_pyg69
by country : summarize we_pyg69

* LFP - YUG RECENT
by country : summarize ml_pyg15
by country : summarize wl_pyg15
* LFP - YUG VETERAN
by country : summarize ml_pyg69
by country : summarize wl_pyg69

log close


